package com.heima.wemedia.controller.v2;

import com.heima.apis.admin.lAdminClient;
import com.heima.model.common.dtos.PageRequestDto;
import com.heima.model.common.dtos.PageSensitive;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmSensitiveDto;
import com.heima.model.wemedia.pojos.WmSensitive;
import com.heima.wemedia.service.WmSensitiveService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/api/v1/sensitive")
@Slf4j
public class SensitivesClient implements lAdminClient {
    @Autowired
    private WmSensitiveService wmSensitiveService;

    @PostMapping("/list")
    public ResponseResult list(@RequestBody PageSensitive pageSensitive){
        log.info("铭感词在这里");
        ResponseResult sensitiveslist = wmSensitiveService.Sensitiveslist(pageSensitive);
        return sensitiveslist;
    }

    @Override
    public ResponseResult getChannels() {
        return null;
    }

    @PostMapping("/update")
    public ResponseResult update(@RequestBody WmSensitive wmSensitive){
        WmSensitive wm = new WmSensitive();
        wm.setSensitives(wmSensitive.getSensitives());
        wm.setId(wmSensitive.getId());
        wmSensitiveService.updateById(wm);
        return ResponseResult.okResult("OK");
    }
    @PostMapping("/save")
    public ResponseResult save(@RequestBody WmSensitive wmSensitive){
        wmSensitive.setCreatedTime(new Date());
        wmSensitiveService.save(wmSensitive);
        return ResponseResult.okResult("ok");
    }
    @DeleteMapping("/del/{id}")
    public ResponseResult delete(@PathVariable Long id){
        wmSensitiveService.removeById(id);
        return ResponseResult.okResult("ok");
    }
}
